-
-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a standalone Modal layout #7083
base: main
Are you sure you want to change the base?
Conversation
panel/layout/modal.py
Outdated
|
||
width = param.Integer(default=None, bounds=(0, None)) | ||
|
||
is_open = param.Boolean(default=False, readonly=True, doc="Whether the modal is open.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this PR.
I've experienced that for some use cases I would like the open
and close
methods. For some it was better if I could set is_open=True
or is_open=False
. Please consider the last feature :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarcSkovMadsen I also missed these two methods in panel_modal. I ended up using modal._show()
.
@@ -0,0 +1,42 @@ | |||
from __future__ import annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When adding documentation please consider if request awesome-panel/panel-modal#3 should be part of the docs. Thx.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7083 +/- ##
==========================================
- Coverage 82.21% 82.12% -0.09%
==========================================
Files 339 341 +2
Lines 51319 51378 +59
==========================================
+ Hits 42193 42196 +3
- Misses 9126 9182 +56 ☔ View full report in Codecov by Sentry. |
This is an excellent addition. I'm a heavy user of panel_modal, and always wished that it shipped together with panel. Modal windows allow me to save a lot of space in the app. One thing I couldn't get panel_modal to do is to update graphs once they have been created (Tabulator meanwhile updates fine), I hope this development will address it. |
Anything I can help with to get this PR merged? |
No, but thank you for asking. I will soon start working on this again. |
@@ -0,0 +1,62 @@ | |||
from __future__ import annotations | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to consider is if the Modal
could be made easier to use? Could the api of the Modal
be generalized to a concept of actions/ action buttons.
Could the api be simplified?
The api of panel-modal
that I made is:
import panel as pn
from panel_modal import Modal
pn.extension("modal")
modal = Modal(pn.panel("Hi. I am the Panel Modal!", width=200))
pn.Column(modal.param.open, modal).servable()
It requires you define a variable holding the Modal and include both the button (modal.param.open
) and the modal modal
.
If you want to customize the button it requires something like pn.widgets.Button.from_param(modal.param.open
as well.
Could the api be simplified? Could it be enough to just include the modal?
import panel as pn
from panel_modal import Modal
pn.extension("modal")
pn.Column(
Modal(pn.panel("Hi. I am the Panel Modal!", width=200))
).servable()
That should show the button. And when clicked the modal should open/ close. That would make it much simpler to drop in as you don't need to define a variable holding the Modal
.
If you want to customize the button you can just do:
import panel as pn
from panel_modal import Modal
pn.extension("modal")
pn.Column(
pn.widgets.Button.from_param(
Modal(
pn.panel("Hi. I am the Panel Modal!", width=200),
),
button_style="outline",
)
)
).servable()
If you want to trigger the modal from something else than a Button than you should be able to hide the button:
import panel as pn
from panel_modal import Modal
pn.extension("modal")
modal = Modal(..., visible=False)
...
def trigger_modal():
modal.open=True
pn.Column(
modal,
.....
).servable()
Could the API be generalized?
A Modal is actually a part of a general concept for action buttons. You want to be able to trigger an action via a Button. You want to be able to easily set the source or target (object
) and be able to customize the button.
modal_button = ModalButton(object=pn.panel(...))
copy_text_button= CopyToClipboardButton(object="...my code")
copy_dataframe_button= CopyToClipboardButton(object=df) # df is a dataframe
paste_button = PasteFromClipboardButton(object=pn.widgets.Tabulator) # Here the object is the target. Not the source.
link_button = OpenLinkButton(object="https://panel.holoviz.org, target="_blank")
maximize_content = pn.Column(...)
maximize_button = MaximizeButton(object=maximize_content) # Maximizes the object to full window size
...
I've had in the back of my head that I wanted to create a panel-action-buttons
package one day. Compiling these as I use those for my work app all the time.
@philippjfr. What do you think?
Fixes #4700
Heavily inspired by https://github.com/awesome-panel/panel-modal. Thank you @MarcSkovMadsen ❤️
screen-recording-2024-08-06_13.32.58.mp4
TO DO:
window as any
.